#include <Arduino.h>
#include <lvgl.h>
#include <ui.h>
#include "global_valuables.h"


void taskSerialMonitor(void * ptr){
    static String data;
	for(;;) {
		if(Serial.available()){
			data = Serial.readStringUntil('\n');
        	Serial.println(data);
			lv_textarea_add_text(ui_TextAreaMonitor, data.c_str());
			lv_timer_handler();
      		lv_task_handler();
		}
		vTaskDelay(10);
	}
}


void FuncStopMotor1(lv_event_t * e)
{
	// Your code here
	Serial.printf(":0 0\r\n");
	sending = false;
}

void FuncStartMotor1(lv_event_t * e)
{
	// Your code here
	static int spd ;
	spd = lv_slider_get_value(ui_Slider1);
	Serial.printf(":0 %d\r\n", spd);
	reaped_send = ":0 " + String(spd) + "\r\n";
	sending = true;
}

void FuncStopMotor2(lv_event_t * e)
{
	Serial.printf(":1 0\r\n");
	sending = false;
}

void FuncStartMotor2(lv_event_t * e)
{
	// Your code here
	static int spd ;
	spd = lv_slider_get_value(ui_Slider3);
	Serial.printf(":1 %d\r\n", spd);
	reaped_send = ":1 " + String(spd) + "\r\n";
	sending = true;
}

void FuncStopMotor3(lv_event_t * e)
{
	Serial.printf(":2 0\r\n");
	sending = false;
}

void FuncStartMotor3(lv_event_t * e)
{
	static int spd ;
	spd = lv_slider_get_value(ui_Slider4);
	Serial.printf(":2 %d\r\n", spd);
	reaped_send = ":2 " + String(spd) + "\r\n";
	sending = true;
}

void FuncStopMotor4(lv_event_t * e)
{
	Serial.printf(":3 0\r\n");
	sending = false;
}

void FuncStartMotor4(lv_event_t * e)
{
	static int spd ;
	spd = lv_slider_get_value(ui_Slider5);
	Serial.printf(":3 %d\r\n", spd);
	reaped_send = ":3 " + String(spd) + "\r\n";
	sending = true;
}

void FuncEmergencyStop(lv_event_t * e)
{
	// Your code here
	Serial.printf(":0 0\r\n:1 0\r\n:2 0\r\n:3 0\r\n");
	Serial.printf("!RESTART\r\n");
}

void FuncCrearMonitor(lv_event_t * e)
{
	lv_textarea_set_text(ui_TextAreaMonitor, "");
}

void FuncSwitchMonitor(lv_event_t * e)
{
	// Your code here
}
